﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Text.RegularExpressions;
using cfg = System.Configuration;
using GoldPrinter;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using WeifenLuo.WinFormsUI.Docking;

namespace BYManageInfoSystem
{
    public partial class Frm_ItemNewOrder : DockContent
    {
        private DGBY.BLL.SJCKHTTab m_bllSJCKHTTab = new DGBY.BLL.SJCKHTTab();
        private DGBY.BLL.BGCKHTTab m_bllBGCKHTTab = new DGBY.BLL.BGCKHTTab();
        
        private DGBY.BLL.BYBackQingDanTab m_bllBYBackQingDanTab = new DGBY.BLL.BYBackQingDanTab();
        private DGBY.BLL.HxdNoTab m_bllHxdNoTab = new DGBY.BLL.HxdNoTab();
        private DGBY.BLL.BGHAddrTab m_bllBGHAddrTab = new DGBY.BLL.BGHAddrTab();
        private DGBY.BLL.SJPackingTab m_bllSJPackingTab = new DGBY.BLL.SJPackingTab();
        private DGBY.BLL.SJGouHHTTab m_bllSJGouHHTTab = new DGBY.BLL.SJGouHHTTab();
        private DGBY.BLL.PaidanRegisterDetailTab m_bllPaidanRegisterDetailTab = new DGBY.BLL.PaidanRegisterDetailTab();
        private DGBY.BLL.LogRecTab m_bllLogRecTab = new DGBY.BLL.LogRecTab();

        //private DGBY.BLL.FactoryDataTab m_bllFactoryDataTab = new DGBY.BLL.FactoryDataTab();
        private DGBY.BLL.BYCompanyTab m_bllBYCompanyTab = new DGBY.BLL.BYCompanyTab();
        private DGBY.BLL.BYDepartTab m_bllBYDepartTab = new DGBY.BLL.BYDepartTab();
        private DGBY.BLL.BYDepCodeTab m_bllBYDepCodeTab = new DGBY.BLL.BYDepCodeTab();
        private DGBY.BLL.T_ACL_User m_bllT_ACL_User = new DGBY.BLL.T_ACL_User();
        private DGBY.BLL.FactoryDataTab m_bllFactoryDataTab = new DGBY.BLL.FactoryDataTab();
        private DGBY.BLL.FacConPeoAndTelTab m_bllFacConPeoAndTelTab = new DGBY.BLL.FacConPeoAndTelTab();
        private DGBY.BLL.PaidanRegisterTab m_bllPaidanRegisterTab = new DGBY.BLL.PaidanRegisterTab();
        private DataSet m_ds = new DataSet();
        private int m_nSelectPaidanRegisterTabID = 0;

        //protected string templetFilePath = cfg.ConfigurationSettings.AppSettings["TempletFilePath"];
        //ExcelBase eB = new ExcelBase();
        //private Dictionary<string, string> dicQueryCondition = new Dictionary<string, string>();

        //string m_strQueryWhere = "";

        public Frm_ItemNewOrder()
        {
            InitializeComponent();
        }
      
        private void Frm_ItemNewOrder_Load(object sender, EventArgs e)
        {
            
            InitCombox();
            //InitQueryCondition();
            ClassUltraGridCommonSet.LocalPrintPreveiw();
            //this.dateTimePickerOrderDate.Value = DateTime.Now.Date;
        }
        
        private void InitCombox()
        {
            this.comboBoxShowWay.Items.AddRange(new object[] { "最近半年记录", "全部记录" });
            this.comboBoxShowWay.SelectedIndex = 0;

            DataSet ds = m_bllBYCompanyTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxComp.DataSource = ds.Tables[0];
                this.comboBoxComp.DisplayMember = "经营单位名称";
                this.comboBoxComp.ValueMember = "BYCompanyTabID";
                this.comboBoxComp.SelectedIndex = 0;
            }
            
            ds = m_bllBYDepartTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxDept.DataSource = ds.Tables[0];
                this.comboBoxDept.DisplayMember = "部门名称";
                this.comboBoxDept.ValueMember = "BYDepartTabID";
                this.comboBoxDept.SelectedIndex = 0;
            }

            ds = m_bllT_ACL_User.GetList("Name != 'System1'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxOrderPerson.DataSource = ds.Tables[0];
                this.comboBoxOrderPerson.DisplayMember = "用户名称";
                this.comboBoxOrderPerson.ValueMember = "UserPasswordTabID";
                this.comboBoxOrderPerson.SelectedValue = Frm_Main.m_nLoginUserId;
            }

            ds = m_bllFactoryDataTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxOrderCustom.DataSource = ds.Tables[0];

                this.comboBoxOrderCustom.ValueMember = "FactoryDataTabID";
                this.comboBoxOrderCustom.DisplayMember = "工厂简称";
                this.comboBoxOrderCustom.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxOrderCustom.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxOrderCustom.SelectedIndex = 0;
            }

            ds = m_bllFactoryDataTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxFeeFac.DataSource = ds.Tables[0];

                this.comboBoxFeeFac.ValueMember = "FactoryDataTabID";
                this.comboBoxFeeFac.DisplayMember = "工厂简称";
                this.comboBoxFeeFac.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxFeeFac.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxFeeFac.SelectedIndex = 0;
            }
            ds = m_bllBYBackQingDanTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxChuKouWay.DataSource = ds.Tables[0];

                this.comboBoxChuKouWay.ValueMember = "BYBackQingDanTabID";
                this.comboBoxChuKouWay.DisplayMember = "出口方式";
                this.comboBoxChuKouWay.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxChuKouWay.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxChuKouWay.SelectedValue = 15;
            }
        }
        
        private void comboBoxOrderCustom_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string str = this.comboBoxOrderCustom.SelectedValue.ToString();
                this.comboBoxOrderContactP.DataSource = null;
                int nID = Convert.ToInt32(str, 10);
                this.comboBoxFeeFac.SelectedValue = nID;

                DataSet ds = m_bllFacConPeoAndTelTab.GetList("FactoryDataTabID = '" + nID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    this.comboBoxOrderContactP.DataSource = ds.Tables[0];
                    this.comboBoxOrderContactP.DisplayMember = "FacConPeoName";
                    this.comboBoxOrderContactP.ValueMember = "FacConPeoAndTelTabID";
                    this.comboBoxOrderContactP.SelectedIndex = 0;
                }
                ds = m_bllFactoryDataTab.GetList("FactoryDataTabID = '" + nID + "'");
                                
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    this.comboBoxDept.SelectedValue = Convert.ToInt32(ds.Tables[0].Rows[0]["BYDepartTabID"].ToString(), 10);
                    this.comboBoxComp.SelectedValue = Convert.ToInt32(ds.Tables[0].Rows[0]["BYCompanyTabID"].ToString(), 10);
                }


                
            }
            catch { }
        }

        //[Logging(BusinessName = "显示所有派单")]
        private void ShowAllRecordInDataGridView(string strWhere)
        {
            ultraGrid1.DataSource = null;
            m_ds = m_bllPaidanRegisterTab.GetAllPaiDanList(strWhere);
            //m_ds = m_bllBGHAddrTab.TestProc();
            if (m_ds.Tables.Count > 0 && m_ds.Tables[0].Rows.Count > 0)
            {
                ultraGrid1.DataSource = m_ds.Tables[0];
                ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
     //           this.ultraGrid1.DisplayLayout.Bands[0].Columns[1].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Button;
               // this.ultraGrid1.DisplayLayout.Bands[0].Columns["落单客户简称"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
   
            }
        }
        private void ShowAllRecordInDataGridViewEx()
        {



            string strTemp = this.comboBoxShowWay.Text;
            if (strTemp == "全部记录")
                ShowAllRecordInDataGridView("");
            else
            {
                DateTime dtNow = System.DateTime.Now.Date.AddDays(-180);
                ShowAllRecordInDataGridView("PaidanRegisterTab.PaiDanDate >= '" + dtNow + "'");
            }
        }
        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecordInDataGridViewEx();
        }

        private string GetNewContractCode(string strDeptCode, string strYear)
        {
            string strHTCode = strDeptCode + strYear + "-";
            int nTotalNum = 0;
            DataSet ds = m_bllPaidanRegisterTab.GetContractCode3Count(strDeptCode, strYear);
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                nTotalNum = (int)ds.Tables[0].Rows[0]["IDCount"];
                if (ds.Tables[0].Rows[0]["IDCount"].ToString() == "0")
                {
                    strHTCode = strHTCode + "001";
                    return strHTCode;
                }

                ds = m_bllPaidanRegisterTab.GetAllContractCode3(strDeptCode, strYear);


                int i = 0;
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strMAXContractCode = "";
                    string strTempMax = "";
                    for(i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        string strTemp = strDeptCode + strYear + "-" + string.Format("{0:d3}", i+1);
                        strTempMax = strDeptCode + strYear + "-" + string.Format("{0:d3}", i + 2); 
                        if (ds.Tables[0].Rows[i]["ContractCode"].ToString().CompareTo(strTemp) != 0)//找中间空的
                        {
                            strMAXContractCode = strTemp;
                            break;
                        }
                    }

                    if (nTotalNum >= 999)
                    {
                        if (i == ds.Tables[0].Rows.Count)
                        {
                            ds = m_bllPaidanRegisterTab.GetAllContractCode4Ex(strDeptCode, strYear);
                            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                            {
                                bool bFind = false;
                                for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                                {
                                    string strTemp = strDeptCode + strYear + "-" + string.Format("{0:d4}", i + 1000);
                                    if (ds.Tables[0].Rows[i]["ContractCode"].ToString().CompareTo(strTemp) != 0)
                                    {
                                        strMAXContractCode = strTemp;
                                        bFind = true;
                                        break;
                                    }
                                }
                                if (!bFind)
                                {
                                    string strCurMax = ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1]["ContractCode"].ToString();
                                    long nDJNo = 0;
                                    if (strCurMax != "")
                                        strCurMax = strCurMax.Substring(strCurMax.Length - 4, 4);

                                    nDJNo = Convert.ToInt64(strCurMax, 10);
                                    nDJNo++;
                                    string strTemp = "";
                                    if (strCurMax != "")
                                        strTemp = string.Format("{0:d4}", nDJNo);
                                    strMAXContractCode = strDeptCode + strYear + "-" + strTemp;
                                }

                            }
                            else
                            {
                                strMAXContractCode = strDeptCode + strYear + "-" + string.Format("{0:d4}", 1000);
                            }
                        }
                    }
                    else if(strMAXContractCode == "")
                    {
                        strMAXContractCode = strTempMax;
                    }
                    //string strMAXContractCode = ds.Tables[0].Rows[i]["ContractCode"].ToString();
                    strMAXContractCode = strMAXContractCode.Substring(6, strMAXContractCode.Length - 6);
                    //int nMAXContractCode = i+1;
                    //  int nMAXContractCode = i+1;
                    int nMAXContractCode = Convert.ToInt32(strMAXContractCode, 10);
                    StringBuilder strHTCodeBuilder = new StringBuilder();
                    strHTCodeBuilder.Append(strHTCode);

                    strHTCodeBuilder.Append(string.Format("{0:d" + strMAXContractCode.Length .ToString()+ "}", nMAXContractCode));


                    return strHTCodeBuilder.ToString();
                }

            }

            return "";
        }
        private void AddPaidanRegisterDetailTab(string strContractCode)
        {

            int nPaidanRegisterTabID = 0;
            DataSet ds = m_bllPaidanRegisterTab.GetAllPaiDanList("PaidanRegisterTab.ContractCode = '" + strContractCode + "'");

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                nPaidanRegisterTabID = (int)ds.Tables[0].Rows[0]["PaidanRegisterTabID"];
            }

            ds = m_bllPaidanRegisterDetailTab.GetList("PaidanRegisterDetailTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'", false);

            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                return;
            }
            DGBY.Model.PaidanRegisterDetailTab modelPaidanRegisterDetailTab
                = new DGBY.Model.PaidanRegisterDetailTab();

            modelPaidanRegisterDetailTab.PaidanRegisterTabID = nPaidanRegisterTabID;
            modelPaidanRegisterDetailTab.GouHuoContractDate = DateTime.Parse("1900-01-01");
            modelPaidanRegisterDetailTab.BusinessDate = DateTime.Parse("1900-01-01");
            modelPaidanRegisterDetailTab.BackTaxDate = DateTime.Parse("1900-01-01");
            modelPaidanRegisterDetailTab.Note = "";

            m_bllPaidanRegisterDetailTab.Add(modelPaidanRegisterDetailTab);



        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string strDeptCodeTemp = "";
                DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = new DGBY.Model.PaidanRegisterTab();

                modelPaidanRegisterTab.DingDanCode = this.textBoxOrderNo.Text;
                modelPaidanRegisterTab.LCCode = this.textBoxLCNo.Text;
                modelPaidanRegisterTab.Note = this.textBoxNote.Text;
                //modelPaidanRegisterTab.ContractCode = this.textBoxContractNo.Text;

                if (this.comboBoxComp.SelectedValue != null)
                    modelPaidanRegisterTab.BYCompanyTabID = Convert.ToInt32(this.comboBoxComp.SelectedValue.ToString(), 10);
                if (this.comboBoxDept.SelectedValue != null)
                {
                    modelPaidanRegisterTab.BYDepartTabID = Convert.ToInt32(this.comboBoxDept.SelectedValue.ToString(), 10);
                    DataSet ds = m_bllBYDepCodeTab.GetList("BYDepartTabID = " + modelPaidanRegisterTab.BYDepartTabID.ToString());
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        strDeptCodeTemp = ds.Tables[0].Rows[0]["DepCodeName"].ToString();
                    }
                }
                if (this.comboBoxOrderPerson.SelectedValue != null)
                    modelPaidanRegisterTab.UserPasswordTabID = Convert.ToInt32(this.comboBoxOrderPerson.SelectedValue.ToString(), 10);
                if (this.comboBoxOrderContactP.SelectedValue != null)
                    modelPaidanRegisterTab.FacConPeoAndTelTabID = Convert.ToInt32(this.comboBoxOrderContactP.SelectedValue.ToString(), 10);

                if (this.comboBoxFeeFac.SelectedValue != null)
                    modelPaidanRegisterTab.FactoryDataTabID = Convert.ToInt32(this.comboBoxFeeFac.SelectedValue.ToString(), 10);
                if (this.comboBoxChuKouWay.SelectedValue != null)
                    modelPaidanRegisterTab.BYBackQingDanTabID = Convert.ToInt32(this.comboBoxChuKouWay.SelectedValue.ToString(), 10);

                if (Frm_Main.m_nLoginUserId != modelPaidanRegisterTab.UserPasswordTabID && Frm_Main.m_strLoginUser != "吴婉玲")
                {
                    MessageBox.Show("只能派自己的单!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (modelPaidanRegisterTab.BYBackQingDanTabID == 15)
                {
                    MessageBox.Show("出口方式不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                modelPaidanRegisterTab.PaiDanDate = DateTime.Now.Date;

                string strYear = modelPaidanRegisterTab.PaiDanDate.Year.ToString();
                string strYearTemp = strYear.Substring(2, 2);
                //this.textBoxContractNo.Text = GetNewContractCode(strDeptCodeTemp, strYearTemp);
                //modelPaidanRegisterTab.ContractCode = GetNewContractCode(strDeptCodeTemp, strYearTemp);
                modelPaidanRegisterTab.ContractCode = this.textBoxContractNo.Text;
                int nResult = m_bllPaidanRegisterTab.Add(modelPaidanRegisterTab);
                AddHxdNoTab(nResult);
                ShowAllRecordInDataGridView("PaidanRegisterTab.ContractCode = '" + modelPaidanRegisterTab.ContractCode + "'");
                //MessageBox.Show("数据添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //this.textBoxContractNo.Text = modelPaidanRegisterTab.ContractCode;
                this.textBoxContractNo.Text = "";
                AddPaidanRegisterDetailTab(modelPaidanRegisterTab.ContractCode);
                this.comboBoxChuKouWay.SelectedValue = 15;
                Frm_Main.Log2DB(this.Text, "手动增加", modelPaidanRegisterTab.ContractCode);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
           
        }
        //不需要的有香港运输，报关，纸箱证，检测费
        private void ModifyTruePayFacID(int nPaidanRegisterTabID, int nFacID)
        {
            try
            {
                //商检
                string strSql = @"update FeeSJTruePayTab set FeeSJTruePayTab.FactoryDataTabID =  '" 
                    + nFacID + "'"  + " where FeeSJTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'";

                m_bllSJPackingTab.ExecuteSql(strSql);
                //大陆船务
                strSql = @"update FeeDLCWTruePayTab set FeeDLCWTruePayTab.FactoryDataTabID =  '"
           + nFacID + "'" + "where FeeDLCWTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'";

                m_bllSJPackingTab.ExecuteSql(strSql);

                //单证
                strSql = @"update FeeDZTruePayTab set FeeDZTruePayTab.FactoryDataTabID =  '"
        + nFacID + "'" + "where FeeDZTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'";

                m_bllSJPackingTab.ExecuteSql(strSql);
                //香港船务
                strSql = @"update FeeHKCWTruePayTab set FeeHKCWTruePayTab.FactoryDataTabID =  '"
    + nFacID + "'" + "where FeeHKCWTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'";

                m_bllSJPackingTab.ExecuteSql(strSql);
                //DHL
                strSql = @"update FeeDHLTruePayTab set FeeDHLTruePayTab.FactoryDataTabID =  '"
+ nFacID + "'" + "where FeeDHLTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'";

                m_bllSJPackingTab.ExecuteSql(strSql);
                //大陆运输
                strSql = @"update FeeDLYSTruePayTab set FeeDLYSTruePayTab.FactoryDataTabID =  '"
+ nFacID + "'" + "where FeeDLYSTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'";

                m_bllSJPackingTab.ExecuteSql(strSql);


            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
       
        private void ModifyTruePayCompID(int nPaidanRegisterTabID, int nCompID)
        {
            try
            {
                //商检
                string strSql = @"update FeeSJTruePayTab set FeeSJTruePayTab.BYCompanyTabID =  '"
                    + nCompID + "'" 
                    + " where FeeSJTruePayTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'";

                m_bllSJPackingTab.ExecuteSql(strSql);
              


            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }

        private void TryChangeTransWayInContract(int nPaidanRegisterTabID, int nBYBackQingDanTabID)
        {
            try
            {
                DataSet ds = m_bllBGCKHTTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    int nBGCKHTTabID = (int)ds.Tables[0].Rows[0]["BGCKHTTabID"];
                    DGBY.Model.BGCKHTTab modelBGCKHTTab = m_bllBGCKHTTab.GetModel(nBGCKHTTabID);

                    ds = m_bllPaidanRegisterTab.GetTransWay("PaidanRegisterTab.BYBackQingDanTabID = '" + nBYBackQingDanTabID + "'");

                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelBGCKHTTab.YSMethodTabID = (int)ds.Tables[0].Rows[0]["YSMethodTabID"];
                        m_bllBGCKHTTab.Update(modelBGCKHTTab);
                    }
                }

                ds = m_bllSJCKHTTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    int nSJCKHTTabID = (int)ds.Tables[0].Rows[0]["SJCKHTTabID"];
                    DGBY.Model.SJCKHTTab modelSJCKHTTab = m_bllSJCKHTTab.GetModel(nSJCKHTTabID);

                    ds = m_bllPaidanRegisterTab.GetTransWay("PaidanRegisterTab.BYBackQingDanTabID = '" + nBYBackQingDanTabID + "'");

                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelSJCKHTTab.YSMethodTabID = (int)ds.Tables[0].Rows[0]["YSMethodTabID"];
                        m_bllSJCKHTTab.Update(modelSJCKHTTab);
                    }
                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        private void ModifySjGHContractRec(int nPaidanRegisterTabID)
        {
            try
            {
                DataSet ds = m_bllSJGouHHTTab.GetList("PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    int nID = (int)ds.Tables[0].Rows[0]["SJGouHHTTabID"];
                    DGBY.Model.SJGouHHTTab modelSJGouHHTTab = m_bllSJGouHHTTab.GetModel(nID);



                    ds = m_bllPaidanRegisterTab.GetFacAddrByContract("PaidanRegisterTab.PaidanRegisterTabID = '" + nPaidanRegisterTabID + "'");

                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelSJGouHHTTab.FacAddrTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["FacAddrTabID"].ToString(), 10);
                    }



                    m_bllSJGouHHTTab.Update(modelSJGouHHTTab);
                }
                

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        private void buttonModify_Click(object sender, EventArgs e)
        {
            try
            {
                DGBY.Model.PaidanRegisterTab modelPaidanRegisterTabOld = m_bllPaidanRegisterTab.GetModel(m_nSelectPaidanRegisterTabID);
                if (modelPaidanRegisterTabOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (modelPaidanRegisterTabOld.ContractCode == "")
                {
                    MessageBox.Show("该合同号为系统合同号，不能修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;

                }
                if (Frm_Main.m_nLoginUserId != modelPaidanRegisterTabOld.UserPasswordTabID)
                {
                    MessageBox.Show("该合同号不是你派的单，不能修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                int nOldBYBackQingDanTabID = modelPaidanRegisterTabOld.BYBackQingDanTabID;
                //DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = new DGBY.Model.PaidanRegisterTab();

                //modelPaidanRegisterTab.PaidanRegisterTabID = m_nSelectPaidanRegisterTabID;
                modelPaidanRegisterTabOld.DingDanCode = this.textBoxOrderNo.Text;
                modelPaidanRegisterTabOld.LCCode = this.textBoxLCNo.Text;
                modelPaidanRegisterTabOld.Note = this.textBoxNote.Text;
                string strOldNo = modelPaidanRegisterTabOld.ContractCode;
                if (modelPaidanRegisterTabOld.ContractCode != this.textBoxContractNo.Text)
                {
                    DialogResult dr = MessageBox.Show("确实要将合同号" + modelPaidanRegisterTabOld.ContractCode + "修改为" + this.textBoxContractNo.Text + "么？", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dr == DialogResult.OK)
                    {
                        modelPaidanRegisterTabOld.ContractCode = this.textBoxContractNo.Text;

                    }
                    else
                    {
                        return;
                    }
                }
                bool bCompChange = false;
                int nCompID = Convert.ToInt32(this.comboBoxComp.SelectedValue.ToString(), 10);
                if (nCompID != modelPaidanRegisterTabOld.BYCompanyTabID)
                    bCompChange = true;

                if (this.comboBoxComp.SelectedValue != null)
                    modelPaidanRegisterTabOld.BYCompanyTabID = Convert.ToInt32(this.comboBoxComp.SelectedValue.ToString(), 10);
                if (this.comboBoxDept.SelectedValue != null)
                    modelPaidanRegisterTabOld.BYDepartTabID = Convert.ToInt32(this.comboBoxDept.SelectedValue.ToString(), 10);
                if (this.comboBoxOrderPerson.SelectedValue != null)
                    modelPaidanRegisterTabOld.UserPasswordTabID = Convert.ToInt32(this.comboBoxOrderPerson.SelectedValue.ToString(), 10);

                bool bFacChange = false;
                int nNewFaConPeocID = Convert.ToInt32(this.comboBoxOrderContactP.SelectedValue.ToString(), 10);
                if (nNewFaConPeocID != modelPaidanRegisterTabOld.FacConPeoAndTelTabID)
                    bFacChange = true;
                
                if (this.comboBoxOrderContactP.SelectedValue != null)
                    modelPaidanRegisterTabOld.FacConPeoAndTelTabID = Convert.ToInt32(this.comboBoxOrderContactP.SelectedValue.ToString(), 10);

                if (modelPaidanRegisterTabOld.BYBackQingDanTabID != 15 && (int)this.comboBoxChuKouWay.SelectedValue == 15)
                {
                    MessageBox.Show("出口方式不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (this.comboBoxChuKouWay.SelectedValue != null)
                    modelPaidanRegisterTabOld.BYBackQingDanTabID = Convert.ToInt32(this.comboBoxChuKouWay.SelectedValue.ToString(), 10);

                if (nOldBYBackQingDanTabID != modelPaidanRegisterTabOld.BYBackQingDanTabID)
                {
                    TryChangeTransWayInContract(m_nSelectPaidanRegisterTabID, modelPaidanRegisterTabOld.BYBackQingDanTabID);
                }

                if (this.comboBoxFeeFac.SelectedValue != null)
                    modelPaidanRegisterTabOld.FactoryDataTabID = Convert.ToInt32(this.comboBoxFeeFac.SelectedValue.ToString(), 10);
                

               // modelPaidanRegisterTabOld.PaiDanDate = DateTime.Now.Date;

                DGBY.Model.LogRecTab modelLogRecTab = new DGBY.Model.LogRecTab();
                modelLogRecTab.LogDate = System.DateTime.Now.Date;
                modelLogRecTab.LogContent = Frm_Main.m_strLoginUser + "修改了合同号" + strOldNo + "为" + modelPaidanRegisterTabOld.ContractCode;
                m_bllLogRecTab.Add(modelLogRecTab);





                m_bllPaidanRegisterTab.Update(modelPaidanRegisterTabOld);
                if (bFacChange)
                {
                    ModifySjGHContractRec(m_nSelectPaidanRegisterTabID);
                    ModifyTruePayFacID(m_nSelectPaidanRegisterTabID
                        , modelPaidanRegisterTabOld.FactoryDataTabID);
                }

                if (bCompChange)
                {
                    ModifyTruePayCompID(m_nSelectPaidanRegisterTabID
                        , modelPaidanRegisterTabOld.BYCompanyTabID);
                }
                ShowAllRecordInDataGridView("PaidanRegisterTab.PaidanRegisterTabID = '" + m_nSelectPaidanRegisterTabID + "'");
                Frm_Main.Log2DB(this.Text, "修改", modelPaidanRegisterTabOld.ContractCode);
                MessageBox.Show("数据修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
           
        }

        private void buttonDel_Click(object sender, EventArgs e)
        {
            DGBY.Model.PaidanRegisterTab modelPaidanRegisterTabOld = m_bllPaidanRegisterTab.GetModel(m_nSelectPaidanRegisterTabID);
            if (modelPaidanRegisterTabOld == null)
            {
                MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (modelPaidanRegisterTabOld.ContractCode == "")
            {
                MessageBox.Show("该合同号为系统合同号，不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;

            }

            if (Frm_Main.m_nLoginUserId != modelPaidanRegisterTabOld.UserPasswordTabID)
            {
                MessageBox.Show("该合同号不是你派的单，不能删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
            {
                DGBY.Model.LogRecTab modelLogRecTab = new DGBY.Model.LogRecTab();
                modelLogRecTab.LogDate = System.DateTime.Now.Date;
                modelLogRecTab.LogContent = Frm_Main.m_strLoginUser + "删除了合同号" + modelPaidanRegisterTabOld.ContractCode;
                m_bllLogRecTab.Add(modelLogRecTab);

                m_bllPaidanRegisterTab.Delete(m_nSelectPaidanRegisterTabID);

                Frm_Main.Log2DB(this.Text, "删除", modelPaidanRegisterTabOld.ContractCode);
                ShowAllRecordInDataGridViewEx();
                MessageBox.Show("数据删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBoxOrderNo.Text = "";
                this.textBoxLCNo.Text = "";
                this.textBoxNote.Text = "";
                this.textBoxContractNo.Text = "";
                return;
            }
        }

        private void buttonExportToExcel_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }

        
        private void buttonPrint_Click(object sender, EventArgs e)
        {
            this.ultraGridPrintDocument1.Grid = this.ultraGrid1;
            
            this.ultraPrintPreviewDialog1.Document = this.ultraGridPrintDocument1;
            this.ultraPrintPreviewDialog1.ShowDialog(this);
        }
    
        private void Frm_ItemNewOrder_FormClosing(object sender, FormClosingEventArgs e)
        {
            ////eB.Close();
        }

       
        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.LocalPrintPreveiw();

            InitColumnWidth();


        }

        private void InitColumnWidth()
        {
            ultraGrid1.DisplayLayout.Bands[0].Columns["序号"].Width = 30;
            ultraGrid1.DisplayLayout.Bands[0].Columns["合同编号"].Width = 75;
            ultraGrid1.DisplayLayout.Bands[0].Columns["经营单位"].Width = 160;
            ultraGrid1.DisplayLayout.Bands[0].Columns["部门"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["跟单人员"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["落单日期"].Width = 95;
            ultraGrid1.DisplayLayout.Bands[0].Columns["生产厂商"].Width = 170;
            ultraGrid1.DisplayLayout.Bands[0].Columns["生产厂商简称"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["联系人"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["收费工厂简称"].Width = 80;
            ultraGrid1.DisplayLayout.Bands[0].Columns["出口方式"].Width = 100;
            ultraGrid1.DisplayLayout.Bands[0].Columns["LC编号"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["订单号"].Width = 60;
            ultraGrid1.DisplayLayout.Bands[0].Columns["备注"].Width = 100;
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            string strPaidanRegisterTabID = this.ultraGrid1.Rows[this.ultraGrid1.ActiveCell.Row.Index].Cells[0].Text;
            m_nSelectPaidanRegisterTabID = Convert.ToInt32(strPaidanRegisterTabID, 10);
            cellPaidanRegisterTabClick();
        }

        private void cellPaidanRegisterTabClick()
        {
            DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = m_bllPaidanRegisterTab.GetModel(m_nSelectPaidanRegisterTabID);
            if (modelPaidanRegisterTab != null)
            {
                this.textBoxOrderNo.Text = modelPaidanRegisterTab.DingDanCode;
                this.textBoxLCNo.Text = modelPaidanRegisterTab.LCCode;
                this.textBoxNote.Text = modelPaidanRegisterTab.Note;
                this.textBoxContractNo.Text = modelPaidanRegisterTab.ContractCode;
                if (modelPaidanRegisterTab.BYCompanyTabID != null)
                    this.comboBoxComp.SelectedValue = modelPaidanRegisterTab.BYCompanyTabID;
                if (modelPaidanRegisterTab.BYDepartTabID != null)
                    this.comboBoxDept.SelectedValue = modelPaidanRegisterTab.BYDepartTabID;
                if (modelPaidanRegisterTab.UserPasswordTabID != null)
                    this.comboBoxOrderPerson.SelectedValue = modelPaidanRegisterTab.UserPasswordTabID;
                if (modelPaidanRegisterTab.FactoryDataTabID != null)
                    this.comboBoxFeeFac.SelectedValue = modelPaidanRegisterTab.FactoryDataTabID;
                if (modelPaidanRegisterTab.BYBackQingDanTabID != null)
                    this.comboBoxChuKouWay.SelectedValue = modelPaidanRegisterTab.BYBackQingDanTabID;

 
                if (modelPaidanRegisterTab.FacConPeoAndTelTabID != null)
                {
                    DataSet ds = new DataSet();
                    ds = m_bllFacConPeoAndTelTab.GetList("FacConPeoAndTelTabID = " + modelPaidanRegisterTab.FacConPeoAndTelTabID.ToString());
                    this.comboBoxOrderCustom.SelectedValue = Convert.ToInt32(ds.Tables[0].Rows[0]["FactoryDataTabID"].ToString(), 10);
                    this.comboBoxOrderContactP.SelectedValue = modelPaidanRegisterTab.FacConPeoAndTelTabID;
                }
                //this.dateTimePickerOrderDate.Value = (System.DateTime)modelPaidanRegisterTab.PaiDanDate;
            }
            else
            {
                this.textBoxOrderNo.Text = "";
                this.textBoxLCNo.Text = "";
                this.textBoxNote.Text = "";
                this.textBoxContractNo.Text = "";
            }
        }

        private void buttonToSJ_Click(object sender, EventArgs e)
        {
            //DataSet ds = m_bllPaidanRegisterTab.GetAllPaiDanList("PaidanRegisterTab.ContractCode = '" + this.textBoxContractNo.Text + "'");
            //int nId = 0;
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    nId = Convert.ToInt32(ds.Tables[0].Rows[0]["PaidanRegisterTabID"].ToString(), 10);
            //}
            //Frm_CommerCheckFillBoxSheet.m_nPaidanRegisterTabID = nId;
            //Frm_Main.GetMainForm().ShowSJFillBoxSheetForm();
        }

        private void Frm_ItemNewOrder_Activated(object sender, EventArgs e)
        {
            //InitCombox();
        }
 








        private void AddHxdNoTab(int nPaidanID)
        {

            //return;
            try
            {
                DGBY.Model.HxdNoTab modelHxdNoTabOld = new DGBY.Model.HxdNoTab();
                modelHxdNoTabOld.BGDNo = "";
                modelHxdNoTabOld.PaidanRegisterTabID = nPaidanID;
                modelHxdNoTabOld.HxdNo = 0;
                modelHxdNoTabOld.JCHxdDjTabID = 0;

                modelHxdNoTabOld.SBDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.LrHsBgdDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.SdHxdDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.YhxDate = DateTime.Parse("1900-01-01");

                modelHxdNoTabOld.JcwTszldDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.QtddjDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.Note = "";
                modelHxdNoTabOld.WeiTuoBook = "";

                modelHxdNoTabOld.CheckInvoiceDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.CKouDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.TongJDate = DateTime.Parse("1900-01-01");

                modelHxdNoTabOld.HsGHHTDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.HstddjDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.SCKHTdjDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.HZzsInvDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.JcGHHTDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.XbdzldjDate = DateTime.Parse("1900-01-01");

                modelHxdNoTabOld.HsbdzldjDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.ZlccdjDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.HsggzldjDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.TuiShuiZHDate = DateTime.Parse("1900-01-01");

                modelHxdNoTabOld.HSLLDDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.HSTYDDate = DateTime.Parse("1900-01-01");
                modelHxdNoTabOld.HSLCDDate = DateTime.Parse("1900-01-01");

                modelHxdNoTabOld.iswts = false;
                modelHxdNoTabOld.islld = false;
                modelHxdNoTabOld.istyd = false;
                modelHxdNoTabOld.isrcd = false;
                modelHxdNoTabOld.isfxt = false;
                modelHxdNoTabOld.istd = false;
                modelHxdNoTabOld.isckht = false;
                modelHxdNoTabOld.bitInvoiceWithContract = false;

                m_bllHxdNoTab.Add(modelHxdNoTabOld);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        private void buttonAutoAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string strDeptCodeTemp = "";
                DGBY.Model.PaidanRegisterTab modelPaidanRegisterTab = new DGBY.Model.PaidanRegisterTab();

                modelPaidanRegisterTab.DingDanCode = this.textBoxOrderNo.Text;
                modelPaidanRegisterTab.LCCode = this.textBoxLCNo.Text;
                modelPaidanRegisterTab.Note = this.textBoxNote.Text;
                //modelPaidanRegisterTab.ContractCode = this.textBoxContractNo.Text;

                if (this.comboBoxComp.SelectedValue != null)
                    modelPaidanRegisterTab.BYCompanyTabID = Convert.ToInt32(this.comboBoxComp.SelectedValue.ToString(), 10);
                if (this.comboBoxDept.SelectedValue != null)
                {
                    modelPaidanRegisterTab.BYDepartTabID = Convert.ToInt32(this.comboBoxDept.SelectedValue.ToString(), 10);
                    DataSet ds = m_bllBYDepCodeTab.GetList("BYDepartTabID = " + modelPaidanRegisterTab.BYDepartTabID.ToString());
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        strDeptCodeTemp = ds.Tables[0].Rows[0]["DepCodeName"].ToString();
                    }
                }
                if (this.comboBoxOrderPerson.SelectedValue != null)
                    modelPaidanRegisterTab.UserPasswordTabID = Convert.ToInt32(this.comboBoxOrderPerson.SelectedValue.ToString(), 10);
                if (this.comboBoxOrderContactP.SelectedValue != null)
                    modelPaidanRegisterTab.FacConPeoAndTelTabID = Convert.ToInt32(this.comboBoxOrderContactP.SelectedValue.ToString(), 10);
                if (this.comboBoxChuKouWay.SelectedValue != null)
                    modelPaidanRegisterTab.BYBackQingDanTabID = Convert.ToInt32(this.comboBoxChuKouWay.SelectedValue.ToString(), 10);


                if (this.comboBoxFeeFac.SelectedValue != null)
                    modelPaidanRegisterTab.FactoryDataTabID = Convert.ToInt32(this.comboBoxFeeFac.SelectedValue.ToString(), 10);

                if (Frm_Main.m_nLoginUserId != modelPaidanRegisterTab.UserPasswordTabID && Frm_Main.m_strLoginUser != "吴婉玲")
                {
                    MessageBox.Show("只能派自己的单!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (modelPaidanRegisterTab.BYBackQingDanTabID == 15)
                {
                    MessageBox.Show("出口方式不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                modelPaidanRegisterTab.PaiDanDate = DateTime.Now.Date;
          

                string strYear = modelPaidanRegisterTab.PaiDanDate.Year.ToString();
                string strYearTemp = strYear.Substring(2, 2);
                this.textBoxContractNo.Text = GetNewContractCode(strDeptCodeTemp, strYearTemp);
                //modelPaidanRegisterTab.ContractCode = GetNewContractCode(strDeptCodeTemp, strYearTemp);
                modelPaidanRegisterTab.ContractCode = this.textBoxContractNo.Text;
                int nResult = m_bllPaidanRegisterTab.Add(modelPaidanRegisterTab);
                AddHxdNoTab(nResult);
                ShowAllRecordInDataGridView("PaidanRegisterTab.ContractCode = '" + modelPaidanRegisterTab.ContractCode + "'");
                //MessageBox.Show("数据添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //this.textBoxContractNo.Text = modelPaidanRegisterTab.ContractCode;
                this.textBoxContractNo.Text = "";
                AddPaidanRegisterDetailTab(modelPaidanRegisterTab.ContractCode);
                this.comboBoxChuKouWay.SelectedValue = 15;
                Frm_Main.Log2DB(this.Text, "自动增加", modelPaidanRegisterTab.ContractCode);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void Frm_ItemNewOrder_Deactivate(object sender, EventArgs e)
        {
            DataSet ds = m_bllPaidanRegisterTab.GetIndex("ContractCode = '" + this.textBoxContractNo.Text + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                int nIndex = Convert.ToInt32(ds.Tables[0].Rows[0]["PaidanRegisterTabID"].ToString(), 10);
                Frm_Main.m_nContractSelectValue = nIndex;
            }
            
        }

        private void ultraGrid1_ClickCellButton(object sender, CellEventArgs e)
        {
            //if (!StringComparer.Ordinal.Equals(e.Cell.Column.Key, @"是否批量选中"))
            //{
            //    m_bLastModifiedCellIsSelect = false;
            //    return;
            //}
            //m_bLastModifiedCellIsSelect = true;
            //int iIndex = e.Cell.Row.Index;
            //if (iIndex < 0)
            //    return;
            //UltraGridRow CurrentUGR = ultraGrid1.Rows[iIndex];
        }

        private void ultraGrid1_CellChange(object sender, CellEventArgs e)
        {

        }
    }
}